/**
 * 工具栏生成工具
 * @author mayonghua
 * @param config
 * @return
 */
var ToolBar = function(config){
	this.renderTo = config.renderTo == null?'toolBar':config.renderTo;
	this.items = config.items;
}
ToolBar.prototype = {
	init : function(){
		var entity = this;
		for(var i=0;i<entity.items.length;i++){
			var item = entity.items[i];
			if(item!='-'){
				var id = entity.random();
				$(entity.bars(item.pic,item.text,id)).appendTo($('#'+entity.renderTo));
				$("#"+id).mousemove(function(){
					$(this).removeClass("toolBar-item-none").addClass("toolBar-item");
				}).mouseout(function(){
					$(this).removeClass("toolBar-item").addClass("toolBar-item-none");
				});
				if(item.handler!=null){
					$("#"+id).bind('click',item.handler);
				}
			}else {
				$(entity.line()).appendTo($('#'+entity.renderTo));
			}
		}
},
render : function(){
	this.init();
},
bars:function(pic,title,id){
		var item = '<table class="toolBar-item-none" id="'+id+'">';
		item +='<tbody>';
		item +='<tr>';
		item +='<td class="frame-tl"></td>';
		item +='<td class="frame-tc"></td>';
		item +='<td class="frame-tr"></td>';
		item +='</tr>';
		item +='<tr>';
		item +='<td class="frame-ml"></td>';
		item +='<td class="frame-mc"><div class="'+pic+'"></div><div class="title">'+title+'</div></td>';
		item +='<td class="frame-mr"></td>';
		item +='</tr>';
		item +='<tr>';
		item +='<td class="frame-bl"></td>';
		item +='<td class="frame-bc"></td>';
		item +='<td class="frame-br"></td>';
		item +='</tr>';
		item +='</tbody>';
		item +='</table>';
		return item;
	},
	line:function(){
		var  verticalLine = '<span class="verticalLine"></span>';
		return verticalLine;
	},
	random : function(){
		//首先产生一个1000以内的随机数
		var r = Math.round(Math.random()*1000);
		//获得当前的日期
		var date = new Date();
		var year = date.getYear();
		var month = date.getMonth();
		var day = date.getDay();
		var hours = date.getHours();
		var minutes = date.getMinutes();
		var seconds = date.getSeconds();
		//根据日期+随机数生成一个随机ID
		return 'id_'+year+month+day+minutes+seconds+r;
	}
}